--- /dev/null
+/*
+ Copyright (C) 2009 Robert Lipe, robertlipe@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+
+#include "upgrade.h"
+#include "mainwindow.h"
+#include "ui_upgrade.h"
+
+#include <QHttp>
+#include <QUrl>
+#include <QMessageBox>
+#include <QFile>
+#include <QDomDocument>
+#include <QDomNode>
+#include <QDomElement>
+#include <QDomNodeList>
+
+Upgrade::Upgrade(QWidget *parent) :
+ QDialog(parent),
+ m_ui(new Ui::Upgrade)
+{
+ m_ui->setupUi(this);
+}
+
+Upgrade::~Upgrade()
+{
+ delete m_ui;
+}
+
+void Upgrade::changeEvent(QEvent *e)
+{
+ QDialog::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ m_ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+
+Upgrade::updateStatus Upgrade::checkForUpgrade()
+{
+ http = new QHttp;
+
+ connect(http, SIGNAL(requestFinished(int, bool)),
+ this, SLOT(httpRequestFinished(int, bool)));
+ connect(http, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
+ this, SLOT(readResponseHeader(const QHttpResponseHeader &)));
+
+ http->setHost("www.gpsbabel.org");
+ httpRequestId = http->get("/updates.xml");
+
+ return Upgrade::updateUnknown;
+}
+
+void Upgrade::readResponseHeader(const QHttpResponseHeader &responseHeader)
+{
+ switch (responseHeader.statusCode()) {
+ case 200: // Ok
+ case 301: // Moved Permanently
+ case 302: // Found
+ case 303: // See Other
+ case 307: // Temporary Redirect
+ // these are not error conditions
+ break;
+
+ default:
+ QMessageBox::information(this, tr("HTTP"),
+ tr("Download failed: %1.")
+ .arg(responseHeader.reasonPhrase()));
+ httpRequestAborted = true;
+ http->abort();
+ }
+}
+
+void Upgrade::httpRequestFinished(int requestId, bool error)
+{
+ if(error or requestId != httpRequestId) {
+ return;
+ }
+
+ QString oresponse(http->readAll());
+ QDomDocument document;
+ if (!document.setContent(oresponse)) {
+ return;
+ }
+
+ QString response("snore");
+
+ QString currentVersion = "1.3.6"; // FIXME: Work with Khai to pry this out of MainWindow
+ bool allowBeta = false; // TODO: come from prefs or current version...
+
+ QDomNodeList upgrades = document.elementsByTagName("update");
+
+ for (unsigned int i = 0; i < upgrades.length(); i++) {
+ QDomNode upgradeNode = upgrades.item(i);
+ QDomElement upgrade = upgradeNode.toElement();
+
+ QString updateVersion = upgrade.attribute("version");
+ bool updateIsBeta = upgrade.attribute("type") == "beta";
+ bool updateIsMajor = upgrade.attribute("type") == "major";
+ bool updateCandidate = updateIsMajor || (updateIsBeta && allowBeta);
+
+ if(updateVersion > currentVersion && updateCandidate) {
+ response = "<b>A new version of GPSBabel is available</b><br/ >";
+ response += "Your version is " + currentVersion + " <br />";;
+ response += "The latest version is " + updateVersion + " <br />";;
+ break;
+ }
+ }
+
+ // FIXME: this doesn't actually write into the UI's text browser...
+ m_ui->textBrowser->setText(response);
+
+ //QMessageBox::information(this, tr("Finished"), response);
+
+}
--- /dev/null
+#ifndef UPGRADE_H
+#define UPGRADE_H
+/*
+ Copyright (C) 2009 Robert Lipe, robertlipe@gpsbabel.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+
+
+#include <QDialog>
+#include "ui_upgrade.h"
+
+class QHttp;
+class QHttpResponseHeader;
+
+namespace Ui {
+ class Upgrade;
+}
+
+class Upgrade : public QDialog {
+ Q_OBJECT
+public:
+ Upgrade(QWidget *parent = 0);
+ ~Upgrade();
+
+ typedef enum {
+ updateUnknown,
+ updateCurrent,
+ updateNeeded,
+ } updateStatus;
+
+ Upgrade::updateStatus checkForUpgrade(void);
+
+protected:
+ void changeEvent(QEvent *e);
+
+private:
+// Ui::Upgrade *m_ui;
+ Ui_Upgrade *m_ui;
+ QHttp *http;
+ int httpRequestId;
+ bool httpRequestAborted;
+ QString latestVersion;
+
+private slots:
+ void httpRequestFinished(int requestId, bool error);
+// void httpStateChanged(int state);
+ void readResponseHeader(const QHttpResponseHeader &responseHeader);
+
+
+};
+
+#endif // UPGRADE_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Upgrade</class>
+ <widget class="QDialog" name="Upgrade">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>400</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="geometry">
+ <rect>
+ <x>30</x>
+ <y>240</y>
+ <width>341</width>
+ <height>32</height>
+ </rect>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ <widget class="QTextBrowser" name="textBrowser">
+ <property name="geometry">
+ <rect>
+ <x>10</x>
+ <y>10</y>
+ <width>381</width>
+ <height>211</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>Upgrade</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>Upgrade</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>